﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EF5;
using System.Data.Entity.Validation;



namespace DataContextLayer
{
    public class Registration:DatabaseHelper
    {
        
        public Registration()
        {
            
        }


        public Registration(Dictionary<string, string> dictionary)
            : base(dictionary)
        {

        }

        private const string SUCCESS_MESSAGE = "User Created! \n Please Login";
        public string RegistrationSuccessful
        {
            get { return SUCCESS_MESSAGE; }
        }
        

        public bool RegisterUser()
        {
            using (var context = new DclContext())
            {
                if (!CheckPasswordLength()) return false;

                var user = FindUserByEmailOrName(context);


                if (!IsNotEmpty(user))
                {
                    if (InsertUser(context))
                    {
                        Messages = "User Created! \n Please Login";
                        return true;
                    }
                    
                    return false;

                }

                Messages = "User Information Already Exists";
                return false;
            }
        }

       
    }
}
